﻿Imports System.Data.SqlClient
Imports System.Data

Partial Class SelectPage
    Inherits System.Web.UI.Page

    Dim strCon As String
    Dim strCom As String
    Dim objCon As SqlConnection
    Dim objCom As SqlCommand
    Dim dtReader As SqlDataReader


    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        BindData()
    End Sub

    Private Sub BindData()
        strCon = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString.ToString
        objCon = New SqlConnection(strCon)
        objCon.Open()
        strCom = "Select Cus_ID,Cus_FirstName,Cus_LastName From NontananYe_SQLLogin_1.Customer"
        objCom = New SqlCommand(strCom, objCon)

        dtReader = objCom.ExecuteReader
        GridView1.DataSource = dtReader
        GridView1.DataBind()

        dtReader.Close()
        dtReader = Nothing
    End Sub

    Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound
        Dim lblCustomerID As Label = CType(e.Row.FindControl("lblCustomerID"), Label)
        If Not IsNothing(lblCustomerID) Then
            lblCustomerID.Text = e.Row.DataItem("Cus_ID")
        End If

        Dim lblCustomerFirstName As Label = CType(e.Row.FindControl("lblCustomerFirstName"), Label)
        If Not IsNothing(lblCustomerFirstName) Then
            lblCustomerFirstName.Text = e.Row.DataItem("Cus_FirstName")
        End If

        Dim lblCustomerLastName As Label = CType(e.Row.FindControl("lblCustomerLastName"), Label)
        If Not IsNothing(lblCustomerLastName) Then
            lblCustomerLastName.Text = e.Row.DataItem("Cus_LastName")
        End If

        Dim LinkButton1 As LinkButton = CType(e.Row.FindControl("LinkButton1"), LinkButton)
        If Not IsNothing(LinkButton1) Then
            LinkButton1.PostBackUrl = "Edit.aspx?id=" + e.Row.DataItem("Cus_ID").ToString
        End If

        Dim LinkButton2 As LinkButton = CType(e.Row.FindControl("LinkButton2"), LinkButton)
        If Not IsNothing(LinkButton2) Then
            LinkButton2.PostBackUrl = "Delete.aspx?id=" + e.Row.DataItem("Cus_ID").ToString
        End If

    End Sub

End Class
